<template>
  <div @click="onToggle">
    <svg-icon id="guide-full" :icon="isFullscreen ? 'exit-fullscreen' : 'fullscreen'" />
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import screenfull from 'screenfull'

// 是否全屏
const isFullscreen = ref(false)

// 点击事件
const onToggle = () => {
  // 全屏切换
  screenfull.toggle()
}

// 监听 screenfull 变化
const change = () => {
  isFullscreen.value = screenfull.isFullscreen
}

// onMounted 钩子函数，在组件挂载后执行
onMounted(() => {
  // on：绑定监听
  screenfull.on('change', change)
})

// onUnmounted 在组件卸载前执行
onUnmounted(() => {
  // off：取消监听
  screenfull.off('change', change)
})
</script>

<style lang="scss" scoped></style>